package ru.hh.team02.chat.logger;

import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;

public abstract class AbstractLogger {
    private BufferedWriter bufferedWriter;
    private final SimpleDateFormat formatter = new SimpleDateFormat("hh:mm:ss:SSS");

        // constructor for any outputStream (example: System.out)
    public AbstractLogger(OutputStream outputStream) {
        if (outputStream != null) {
            bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream));
        }
    }


    public void write(String string) {
        try {
            if (bufferedWriter != null) {
                bufferedWriter.write(formatter.format(new Date()) + " " + string + "\n");
                bufferedWriter.flush();
            }
        }
        catch (Exception exception) {
             System.out.println("log inside a log");
        }
    }
}
